package adventure.placeable.trigger.conditions;

import player.Player;
import adventure.room.RoomManager;

/**
 *
 * @author Michael Hanns
 *
 */
public class StringCondition extends TriggerCondition implements Cloneable {

    private String value;

    public StringCondition(String condition, String value, boolean not) {
        super(condition,"STRING", not);
        this.value = value;
    }

    public String getStringVal() {
        return value;
    }

    @Override
    public String getDescription() {
        String notTxt;
        if(not()) {
            notTxt = "NOT ";
        } else {
            notTxt = "";
        }
        String description = notTxt + dependant + " " + condition + " " + value;

        return description;
    }

    @Override
    public boolean meetsCondition(RoomManager r, Player p, String i, boolean previousFailed) {
        boolean success = false;
        if (condition.equals("PREVIOUSFAILED")) {
            success = previousFailed;
        } else if (condition.equalsIgnoreCase("EQUALS")) {
            success = condEquals(i);
        } else {
            return false;
        }
        
        if(not()) {
            success = !success;
        }
        
        return success;
    }

    @Override
    public boolean isUserSpecified() {
        if (condition.equalsIgnoreCase("EQUALS")) {
            return true;
        }
        return false;
    }

    private boolean condEquals(String i) {
        if (i != null && i.equalsIgnoreCase(value)) {
            return true;
        } else {
            return false;
        }
    }
}
